import 'dart:async';
import 'dart:math';

import 'package:avatar_glow/avatar_glow.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shishi/Tab/home.dart';
import 'package:shishi/login/login.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../Colors.dart';
import '../bean/randomshi.dart';

class Splash extends StatefulWidget{
  @override
  _Splash createState() => _Splash();

}
class _Splash extends State<Splash> {


  SharedPreferences sharedPreferences;

  String _names;

  int random = Random().nextInt(15);

  _get() async {
    sharedPreferences = await SharedPreferences.getInstance();
    String names = sharedPreferences.getString("name");
    _names = names;
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _get();

    Timer(Duration(seconds: 3),() {
      if(_names == null) {
        Navigator.of(context).pushAndRemoveUntil(
            CupertinoPageRoute(builder: (context) => Login()),
                (route) => route == null
        );
      } else {
        Navigator.of(context).pushAndRemoveUntil(
            CupertinoPageRoute(builder: (context) => Home()),
                (route) => route == null
        );
      }
    });

  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return  Scaffold(
        body: Stack(
          children: <Widget>[
            Container(
              width: MediaQuery.of(context).size.width,
              height: MediaQuery.of(context).size.height,
              child: CachedNetworkImage(
                imageUrl: 'https://scpic.chinaz.net/files/pic/pic9/202107/bpic23776.jpg',
                fit: BoxFit.cover,
              ),
            ),
            Container(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Container(
                    child: Text('曦诗',style: TextStyle(
                        fontFamily: 'lixuke',
                        fontSize: 30,
                        color: Cos.zhutise
                    ),),
                  ),
                  Center(
                    child: AvatarGlow(
                      glowColor: Colors.white,
                      duration: Duration(milliseconds: 400),
                      endRadius: 90.0, //required
                      child: Material(
                        //required
                        elevation: 10.0,
                        shape: CircleBorder(),
                        child: Container(
                          height: 100,
                          width: 100,
                          decoration: BoxDecoration(
                            image: DecorationImage(
                              image: NetworkImage(
                                'https://scpic.chinaz.net/files/pic/pic9/201803/zzpic11109.jpg',
                              ),
                              fit: BoxFit.cover,
                            ),
                            border: Border.all(
                                color: Colors.white, width: 3.0, style: BorderStyle.solid),
                            borderRadius: BorderRadius.circular(90),
                          ),
                        ),
                      ),
                    ),
                  ),

                  Container(
                    child: Text(listshuiji[random]['shi'][0],style: TextStyle(
                      fontFamily: 'lixuke',
                      fontSize: 40,
                      color: Cos.zhutise
                    ),),
                  ),
                  Container(
                    child: Text(listshuiji[random]['shi'][1],style: TextStyle(
                        fontFamily: 'lixuke',
                        fontSize: 40,
                        color: Cos.zhutise
                    ),),
                  ),
                  const SizedBox(
                    height: 30,
                  ),
                  Container(
                    child: Text(listshuiji[random]['title'],style: TextStyle(
                        fontFamily: 'kai',
                        fontSize: 20,
                    ),),
                  ),
                  const SizedBox(
                    height: 10,
                  ),
                  Container(
                    child: Text(listshuiji[random]['author'],style: TextStyle(
                        fontFamily: 'kai',
                        fontSize: 20,
                    ),),
                  ),

                ],
              ),
            ),

          ],
        ),
    );
  }

}
